﻿using Futaba.SBus.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Futaba.SBus.Tests.Configuration
{
	[TestClass]
	public class ModelConfigurationFactoryTests : BaseTest
	{

		[TestMethod, TestCategory("GenerateConfig")]
		[DeploymentItem(@"Samples\TBoxData\flight2.xml")]
		public void Save()
		{
			var target = ModelConfigurationFactory.DefaultInstance;
			var config = new ModelConfiguration();
			config.DisplayName = "Example Model Channel and Telemetry-Configuration";
			config.Channels = Channels.ChannelFactory.DefaultInstance.GetDefaultChannels();
			using (var stream = File.OpenRead("flight2.xml"))
			{
				config.Slots = Futaba.SBus.Telemetry.SlotFactory.DefaultInstance.Load(stream);
			}

			var outFile = Path.Combine(TestContext.TestResultsDirectory, "example_model_configuration.xml");
			using (var stream = File.OpenWrite(outFile))
			{
				target.Save(config, stream);
			}
			Assert.IsTrue(File.Exists(outFile));
			Assert.AreNotEqual(0, new FileInfo(outFile).Length);
			TestContext.AddResultFile(outFile);
		}

	}
}
